package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * 使用预编译SQL执行DELETE语句
 * 需求:根据id删除userinfo表中的记录
 */
public class JDBCDemo9 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection();){
            String sql = "DELETE FROM userinfo WHERE id=?";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setInt(1,2);
            int num = ps.executeUpdate();
            if(num>0){
                System.out.println("删除成功");
            }else{
                System.out.println("删除失败");
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
